<?php
    include('../init.php');
    
    $cid = $_REQUEST['cid'];
    
    $line = $db->queryUniqueObject("SELECT * FROM hs_collection WHERE pc_id=$cid");
    $data['collectGroupList'] = '';
    $data['product'] = 0;
    $y = 0;
    
    $rss2 = $db->query('SELECT * FROM hs_product WHERE pc_id='.$line->pc_id.' AND p_active=1 ORDER BY pc_id DESC');
    if($db->numRows($rss2) > 0){
        $data['collectGroupList'] .= '<ul>';
        $i = 0;
        while ($line2 = $db->fetchNextObject($rss2)){
            if($i==0){
                
                if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img)){
                    $fImg = URL.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img;
                }else if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img))){
                    $fImg = URL.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img);
                }else{
                    $fImg = URL.'/images/noimg.jpg';
                }
                
                $data['fImg'] = $fImg;
                $data['fTitle'] = $line->pc_name;
                $data['fDetail'] = $line->pc_detail;
                $data['fId'] = $line2->p_id;
            }
            
            $class = '';
            if((($i)%4)==0){
                $class='gallery_list_first';
            }
            
            if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img)){
                $fImg = URL.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img;
            }else if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img))){
                $fImg = URL.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img);
            }else{
                $fImg = URL.'/images/noimg.jpg';
            }
            
            $data['collectGroupList'] .= '<li id="'.$line2->p_id.'"><img src="'.$fImg.'" alt="'.$line2->p_name.'" title="'.$line2->p_name.'" class="img_link" /></li>';
            $i++;
            $data['product']++;
        }
        $y++;
        $data['collectGroupList'] .= '</ul>';
    }
    
    echo json_encode($data);
?>